You
can use both SQL Server Management Studio and the system stored
procedures to gather information about linked servers and the
referenced data sources. Following are some of the most-often-used
system stored procedures:
sp_linkedservers— This returns a list of linked servers defined on the local server.
sp_catalogs— This displays a list of catalogs and descriptions for a specified linked server.
sp_indexes— This shows index information for a specified remote table.
sp_primarykeys— This returns the primary key columns for the specified table.
sp_foreignkeys— This lists the foreign keys defined for the remote table.
sp_tables_ex— This displays table information from the linked server.
sp_columns_ex— This returns column information for all columns or a specified column for a remote table.
sp_helplinkedsrvlogin— This displays the linked server login mappings for each linked server.
For example, at query
prototyping time, it is useful to see all the ways the linked server
objects and columns are being referenced (especially when you’re
dealing with other data sources, such as Excel spreadsheets).
First, the exact linked object name is displayed via the sp_tables_ex
system stored procedure. In this case, you would see the following for
the ACCESS_DATABASE_CUSTOMERS linked server just created:
EXECUTE sp_tables_ex 'ACCESS_DATABASE_CUSTOMERS'
go
TABLE_CAT TABLE_SCHEM TABLE_NAME TABLE_TYPE REMARKS
--------- ----------- ------------ ------------ -------
NULL NULL MSysAccessObjects ACCESS TABLE
NULL NULL MSysACEs SYSTEM TABLE
NULL NULL MSysObjects SYSTEM TABLE
NULL NULL MSysQueries SYSTEM TABLE
NULL NULL MSysRelationships SYSTEM TABLE
NULL NULL SWCustomers TABLE
Then you can see all the table columns of that linked server’s data source by using the sp_columns_ex system stored procedure. The following command provides the column definitions for the SWCustomers Access table for the linked server 'ACCESS_DATABASE_CUSTOMERS':
EXECUTE sp_columns_ex 'ACCESS_DATABASE_CUSTOMERS'
go
TABLE_CAT TABLE_SCH TABLE_NAME COLUMN_NAME TYPE_NAME SIZE
------------------------------------- ------------ ---------- -------
NULL NULL MSysAccessObjects Data VarBinary 3992
NULL NULL MSysAccessObjects ID Long 10
NULL NULL SWCustomers CustomerID VarChar 255
NULL NULL SWCustomers CompanyName VarChar 255
NULL NULL SWCustomers ContactName VarChar 255
NULL NULL SWCustomers ContactTitle VarChar 255
NULL NULL SWCustomers Address VarChar 255
NULL NULL SWCustomers City VarChar 255
NULL NULL SWCustomers Region VarChar 255
NULL NULL SWCustomers PostalCode Double 15
NULL NULL SWCustomers Country VarChar 255
NULL NULL SWCustomers Phone VarChar 255
NULL NULL SWCustomers Fax VarChar 255